/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.luxoft.corporate.blog.ui;

import com.luxoft.corporate.blog.db.entities.BlogEntry;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Egor
 */
public class BlogEntryPanel extends JPanel{
    private JLabel publishedDate;
    private JLabel header;
    private JLabel authorName;
    private JEditorPane blogContent;

    public BlogEntryPanel() {
        publishedDate = new JLabel("Pulish date: ");
        header = new JLabel("Title: ");
        authorName = new JLabel("Author:");
        blogContent = new JEditorPane();
        init();
    }
    
    private void init(){
        Box topBox = Box.createHorizontalBox();
        topBox.add(Box.createHorizontalStrut(5));
        topBox.add(publishedDate);
        topBox.add(Box.createHorizontalStrut(5));
        topBox.add(header);
        topBox.add(Box.createHorizontalStrut(5));
        topBox.add(authorName);
        topBox.add(Box.createHorizontalStrut(5));
        
        Box bottomBox = Box.createHorizontalBox();
        bottomBox.add(blogContent);
        
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        
        
        add(topBox);
        add(Box.createVerticalStrut(5));
        add(bottomBox);
    
    }
    
    //Blog entry data bean
    public void setData(BlogEntry blogEntry){
        fillData(blogEntry);
    }
    
    
    private void fillData(BlogEntry blogEntry){
        publishedDate.setText(publishedDate.getText().concat(blogEntry.getPublishDate().toString()));
        header.setText(header.getText().concat(blogEntry.getTopicName()));
        authorName.setText(authorName.getText().concat(blogEntry.getUserName()));
        blogContent.setText(blogEntry.getText());
        
    }
}
